import api from '@/common/request/request.js';
import { INIT_DATA } from './type.js';
const state = {
	data: {
		statusBarHeight: 0,         // 状态栏高度
		navHeight: 0,               // 导航高度
		capHeight: 0,               // 胶囊高度
        safeArea: 0                 // 手机屏幕高度
	},
	user: //登入信息
		{
		id: 0,
		userid: 16287894572156, // 用户ID
		gender: '男',
		birthday: '2020-10-20',
		account: '13024567890', // 账户
		head_img: "/static/img/img_avatar.png", // 头像
		name: "张三",
		tel: 13204567890,
		type: "普通会员",
		status: "已绑定"
		},
    goods_detail: {                 // 商品详情
        base_info: {
            banners:[{                  // 轮播图
                "img": "https://kuaichuang.insunny.cc/temp_img/goods1.png"
            }, {
                "img": "https://kuaichuang.insunny.cc/temp_img/goods1.png"
            }, {
                "img": "https://kuaichuang.insunny.cc/temp_img/goods1.png"
            }],
            bannerfoods:[{                  // 美食频道轮播图
                "img": "https://cdn.jsdelivr.net/gh/foxscallion11/sc1@master/2021/04/28/447e7227ba58b5693397a55c670a4a14.png"
            }, {
                "img": "https://cdn.jsdelivr.net/gh/foxscallion11/sc1@master/2021/04/28/447e7227ba58b5693397a55c670a4a14.png"
            }, {
                "img": "https://cdn.jsdelivr.net/gh/foxscallion11/sc1@master/2021/04/28/447e7227ba58b5693397a55c670a4a14.png"
            }],
            score:8800,                 // 所需积分
            activeScore:100000,         // 划线积分
            exchange:800,               // 已兑换件数
            title: "烤箱北美电器电烤箱家用小型多功能烘焙机全自动小型迷你M12D",         // 标题
            limit: "每人限购一台",        // 购买条件
            is_group: 1,                // 是否为拼团商品
        },
        love: {                         // 猜你喜欢
            title: "猜你喜欢",
            goods: [{
                "img": "https://kuaichuang.insunny.cc/temp_img/goods1.png",
                "label": "九阳迷你形家用电磁炉三年全国保修",
                "value": "8800积分"
            },{
                "img": "https://kuaichuang.insunny.cc/temp_img/goods2.png",
                "label": "飞科剃须刀",
                "value": "6000积分"
            },{
				"img": "https://kuaichuang.insunny.cc/temp_img/goods3.png",
				"label": "beats潮牌全封闭式头戴耳机超高音质",
				"value": "6900积分"
			},{
				"img": "https://kuaichuang.insunny.cc/temp_img/goods4.png",
				"label": "九阳榨汁机",
				"value": "5080积分"
			},{
				"img": "https://kuaichuang.insunny.cc/temp_img/goods5.png",
				"label": "智能门锁",
				"value": "8800积分"
			},{
				"img": "https://kuaichuang.insunny.cc/temp_img/goods6.png",
				"label": "beats有线耳机超高品质深灰",
				"value": "8800积分"
			}]
        },
        adverts: {                      // 商品介绍
            title: "商品介绍",
            advert: [{
                img: "https://kuaichuang.insunny.cc/temp_img/advert1.png"
            },{
                img: "https://kuaichuang.insunny.cc/temp_img/advert2.png"
            }]
        },
    },
    tabbarActive: 2,
	// 選中的下標
	// 商家详情
	notice_detail: {},
	// 商家
	notice: [
		{
			id: 0,
			url: "/pages/seller/detail/index",
			name: "泉州休闲食物",
			img: "/static/img/banner-03.png",
			place: "东海泰禾广场",
			type: "休闲食物",
			address: "泉州市丰泽区东海泰禾广场2楼088号2楼088号",
			distance: 5.29,
			category: "商品",
			num: 100,
			status: true,
			date: "周一至周日 08:00-23:00",
			text: [{
				id: 0,
				label: "代",
				value: "100积分购10元代金券"
			}],
		},
		{
			id: 7,
			url: "/pages/seller/detail/index",
			name: "泉州亲子服装",
			img: "/static/img/banner-03.png",
			place: "东海泰禾广场",
			type: "亲子",
			address: "厦门市",
			distance: 5.29,
			category: "商品",
			num: 100,
			status: true,
			date: "周一至周日 08:00-23:00",
			text: [{
				id: 0,
				label: "代",
				value: "100积分购10元代金券"
			}],
		},
		{
			id: 8,
			url: "/pages/seller/detail/index",
			name: "泉州休闲娱乐服装",
			img: "/static/img/banner-03.png",
			place: "东海泰禾广场",
			type: "休闲娱乐",
			address: "泉州市丰泽区东海泰禾广场2楼088号2楼088号",
			distance: 5.29,
			category: "商品",
			num: 100,
			status: true,
			date: "周一至周日 08:00-23:00",
			text: [{
				id: 0,
				label: "代",
				value: "100积分购10元代金券"
			}],
		},
		{
			id: 1,
			url: "/pages/seller/detail/index",
			name: "泉州生活服务服装",
			img: "/static/img/banner-03.png",
			place: "东海泰禾广场",
			type: "生活服务",
			address: "泉州市丰泽区东海泰禾广场2楼088号2楼088号",
			distance: 5.29,
			category: "商品",
			num: 900,
			status: true,
			date: "周一至周日 08:00-23:00",
			text: [{
				id: 0,
				label: "代",
				value: "100积分购10元代金券"
			}],
		},
		{
			id: 1,
			url: "/pages/seller/detail/index",
			name: "漳州养生保健服装",
			img: "/static/img/banner-03.png",
			place: "万达广场",
			type: "养生保健",
			address: "泉州市丰泽区东海泰禾广场2楼088号2楼088号",
			distance: 3.29,
			category: "商品",
			num: 700,
			status: true,
			date: "周一至周五 09:00-23:00",
			text: [
				{
				id: 0,
				label: "代",
				value: "100积分购10元代金券"
			},
				{
				id: 1,
				label: "代",
				value: "200积分购10元代金券"
			},
			],
		},

	]
	//商品详情
	,
	product: {},
	//商品
	goods: [
		{
			id: 0,
			type: "新品",
			category:"商家",
			img: "https://kuaichuang.insunny.cc/temp_img/goods.png",
			title: "智能无线鼠标智能无线鼠标",
			exchange: "100",
			score: "1000",
			activeScore: "100000",
			limit: 1,
			date: "2021-07-14 17:31:21",
			comment: [],
			distance: 9.20
			
		},
		{
			id: 1,
			category:"商品",
			type: "热门",
			img: "https://kuaichuang.insunny.cc/temp_img/goods.png",
			title: "智能无线鼠标智能无线鼠标",
			exchange: "300",
			score: "2000",
			activeScore: "100000",
			limit: 1,
			date: "2020-07-14 17:31:21",
			distance: 3.20,
			comment: [
				{
					id: 0,
					name: "lisi",
					comment: "hello"
				},{
					id: 1,
					name: "lisi",
					comment: "hello"
				},
			]
		},
		{
			id: 0,
			type: "新品",
			category:"电影票",
			img: "https://kuaichuang.insunny.cc/temp_img/goods.png",
			title: "智能无线鼠标智能无线鼠标",
			exchange: "200",
			score: "3000",
			activeScore: "100000",
			limit: 1,
			date: "2016-07-14 17:31:21",
			distance: 2.20,
			comment: [
				{
					id: 0,
					name: "lisi",
					comment: "hello"
				},
			]
		},

		{
			id: 0,
			type: "新品",
			category:"商家",
			img: "https://kuaichuang.insunny.cc/temp_img/goods.png",
			title: "智能无线鼠标智能无线鼠标",
			exchange: "100",
			score: "4000",
			activeScore: "100000",
			limit: 1,
			date: "2021-07-14 17:31:21",
			comment: [],
			distance: 9.20
			
		},
		{
			id: 1,
			category:"商品",
			type: "热门",
			img: "https://kuaichuang.insunny.cc/temp_img/goods.png",
			title: "智能无线鼠标智能无线鼠标",
			exchange: "300",
			score: "5000",
			activeScore: "100000",
			limit: 1,
			date: "2020-07-14 17:31:21",
			distance: 3.20,
			comment: [
				{
					id: 0,
					name: "lisi",
					comment: "hello"
				},{
					id: 1,
					name: "lisi",
					comment: "hello"
				},
			]
		},
		{
			id: 1,
			category:"商品",
			type: "热门",
			img: "https://kuaichuang.insunny.cc/temp_img/goods.png",
			title: "智能无线鼠标智能无线鼠标",
			exchange: "300",
			score: "7000",
			activeScore: "100000",
			limit: 1,
			date: "2020-07-14 17:31:21",
			distance: 3.20,
			comment: [
				{
					id: 0,
					name: "lisi",
					comment: "hello"
				},{
					id: 1,
					name: "lisi",
					comment: "hello"
				},
			]
		},
		{
			id: 1,
			category:"商品",
			type: "热门",
			img: "https://kuaichuang.insunny.cc/temp_img/goods.png",
			title: "智能无线鼠标智能无线鼠标",
			exchange: "300",
			score: "7000",
			activeScore: "100000",
			limit: 1,
			date: "2020-07-14 17:31:21",
			distance: 3.20,
			comment: [
				{
					id: 0,
					name: "lisi",
					comment: "hello"
				},{
					id: 1,
					name: "lisi",
					comment: "hello"
				},
			]
		},


	],
};

const actions = {
    get_init({commin},payload) {
        return new Promise((resolve, reject) => {
            api('init').then(res => {
                commit('INIT_DATA', res.data);
                console.log(res,'init');
                // 保存一下主题色;
                // uni.setStorageSync('themeKey',res.data.....);
                resolve(res);
            }).catch(e => {
                reject(e);
            })
        })
    },
    get_data({commit}, payload) {
    	commit('set_data', payload)
    },
    get_tabbarActive( {commit }, payload) {
        commit('set_tabbarActive', payload)
    },
    get_goods( {commit }, payload) {
        commit('set_goods', payload)
    },
    get_product( {commit }, payload) {
        commit('set_product', payload)
    },
    get_notice( {commit }, payload) {
        commit('set_notice', payload)
    },
    get_notice_detail( {commit }, payload) {
        commit('set_notice_detail', payload)
    },
    get_user( {commit }, payload) {
        commit('set_user', payload)
    }
};

const mutations = {
	set_data(state,payload){
        for(let key in payload) {
        	state.data[key] = payload[key]
        }
    },
    // 设置全局状态
    [INIT_DATA](state, data) {
        state.init = data;
    },
    set_tabbarActive(state, payload) {
        state.tabbarActive = payload
    },
    set_goods(state, payload) {
        state.goods= payload
    }
	,
    set_product(state, payload) {
        state.product= payload
    }
	,
    set_notice(state, payload) {
        state.notice= payload
    }
	,
    set_notice_detail(state, payload) {
        state.notice_detail= payload
    }
	,
    set_user(state, payload) {
        state.user= payload
    }
};

const getters = {
    
};

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}